<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>修改快递员</span>
			</div>
			<div class="content">
				<table>	
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input class="input inline-input" placeholder="请输入手机号码"> <span id="find1" class="btn btn-info">立即查找</span></td>
					</tr>
				</table>
			</div>
			
			
			<div class="header">
				<span>查找信息如下</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">姓名</td><td class="content_right"><input id="sysname"  class="input" placeholder="请输入姓名"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input id="sysphone" class="input" placeholder="请输入电话"></td>
					</tr>
					<tr>
						<td class="text-right">身份证号码</td><td class="content_right"><input id="cardid" class="input" placeholder="请输入身份证号码"></td>
					</tr>
					<tr>
						<td class="text-right">密码</td><td class="content_right"><input id="password" class="input" placeholder="请输入密码"></td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span id="update" class="btn btn-info">立即修改</span>  </td>
					</tr>
				</table>
			</div>
		</div>
	</body>
	<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>


	<script>
		function isName() {
			var sysname = $("input:eq(1)").val();
			if (sysname == "") {
				layer.tips("姓名不能为空", "#sysname", {tipsMore: true, tips: 1});
				return false;
			} else if (/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(sysname) == false) {      //英文，中文，数字，下划线
				layer.tips("姓名只支持英文、中文、数字和下划线", "#sysname", {tipsMore: true, tips: 1});
				return false;
			}
			return true;
		}

		function isPhone() {
			var sysphone = $("input:eq(2)").val();
			if (sysphone == "") {
				layer.tips("电话不能为空", "#sysphone", {tipsMore: true, tips: 1});
				return false;
			} else if (/^^1[0-9]{10}$$/.test(sysphone) == false) {      //英文，中文，数字，下划线
				layer.tips("电话格式不合法", "#sysphone", {tipsMore: true, tips: 1});
				return false;
			}
			return true;
		}


		function isCardId() {
			var cardid = $("input:eq(3)").val();
			if (cardid == "") {
				layer.tips("身份证号码不能为空", "#cardid", {tipsMore: true, tips: 1});
				return false;
			} else if (/^[1-9]\d{17}/.test(cardid) == false) {      //英文，中文，数字，下划线
				layer.tips("身份证格式不合法", "#cardid", {tipsMore: true, tips: 1});
				return false;
			}
			return true;
		}

		function isPassword() {
			var password = $("input:eq(4)").val();
			if (password == "") {
				layer.tips("密码不能为空", "#password", {tipsMore: true, tips: 1});
				return false;
			} else if (password.length < 6) {      //英文，中文，数字，下划线
				layer.tips("密码位数不能少于6位", "#password", {tipsMore: true, tips: 1});
				return false;
			}
			return true;
		}

	</script>

	<script>
		$(".header:eq(1),.content:eq(1)").hide();
		var g_sysPhone = null;
		var g_id = null;

		$(function () {
			$("input:eq(1)").blur(function () {
				isName();
			});

			$("input:eq(2)").blur(function () {
				isPhone();
			});

			$("input:eq(3)").blur(function () {
				isCardId();
			});

			$("input:eq(4)").blur(function () {
				isPassword();
			});

			$("#find1").click(function () {
				var windowId = layer.load();
				var sysPhone = $("input:eq(0)").val();
				if (sysPhone!=""){
					$.getJSON("/courier/findBySysPhone.do",{sysPhone:sysPhone},function (data) {
						layer.close(windowId);
						layer.msg(data.result);
						if (data.status==0){
							$(".header:eq(1),.content:eq(1)").fadeIn(1000);
							g_sysPhone = data.data.sysPhone;
							g_id = data.data.id;

							$("input:eq(1)").val(data.data.sysName);
							$("input:eq(2)").val(data.data.sysPhone);
							$("input:eq(3)").val(data.data.cardId);
							$("input:eq(4)").val(data.data.password);


						}
					})
				}else{
					layer.close(windowId);
					layer.msg("输入的手机号不能为空");
				}
			})


			$("#update").click(function () {
				var bool = isName() && isPhone() && isCardId() && isPassword();
				if (bool){
					var windowId = layer.load();
					var sysName = $("input:eq(1)").val();
					var sysPhone = $("input:eq(2)").val();
					var cardId = $("input:eq(3)").val();
					var password = $("input:eq(4)").val();


					$.getJSON("/courier/update.do", {id:g_id,sysName:sysName,sysPhone:sysPhone,cardId:cardId,password:password,g_sysPhone:g_sysPhone}, function (data) {
						layer.close(windowId);
						layer.msg(data.result)

						if (data.status == 0) {
							//修改成功的
							$(".header:eq(1),.content:eq(1)").hide();
						}
					})

				}

			})



		})

	</script>


</html>
